<template>
  <a-button shape="round" style="margin-right: 5px" @click="moveUp" icon="arrow-up">
    上移
  </a-button>
</template>
<script>
import {createProps} from '@/utils';

export default {
  name: 'MoveUpButton',
  props: {
    config: createProps(Object, () => undefined),
    context: createProps(Object, () => undefined),
    dataSource: createProps(Array, () => []),
    subFormDefinition: createProps(Object),
    selectedRowId: createProps(String),
  },
  methods: {
    moveUp() {
      let index = this.dataSource.findIndex(item => item.id === this.selectedRowId);
      if(index <= 0) return;
      let index1 = index - 1;
      let temp = this.dataSource[index];
      this.dataSource[index] = this.dataSource[index1];
      this.dataSource[index1] = temp;
      this.dataSource.splice(0, 0);
    },
  }
};
</script>